package com.baizhi.service.impl;

import com.baizhi.annolation.LogAnnotation;
import com.baizhi.dao.AdminDao;
import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;
    @Override
    public boolean login(String userName, String password) {
        Admin admin = adminDao.selectByName(userName);
        System.out.println(admin);
        if (admin!=null && password.equals(admin.getPassWord())){
            System.out.println(admin);
            System.out.println(password+"--------------"+admin.getPassWord());
            return  true;
        }

        return false;
    }

    @Override
    //@LogAnnotation(type = "管理员模块",value="进行了管理员修改")
    public void updateAdmin(Admin admin) {
        adminDao.updateAdmin(admin);
    }

   // @Override
    @LogAnnotation(type = "管理员模块",value="添加了管理员")
    public void insertAdmin(Admin admin) {
        adminDao.insertAdmin(admin);
    }

    @Override
   // @LogAnnotation(type = "管理员模块",value="删除了管理员信息")
    public void deleteAdmin(Integer id) {
        adminDao.deleteAdmin(id);
    }

    @Override
    public Admin selectByName(String userName) {
        return adminDao.selectByName(userName);
    }

    @Override
    //@LogAnnotation(type = "管理员模块",value="查询了所有的管理员信息")
    public Map selectAllAdmin(Integer page, Integer limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;
        int i = adminDao.countAdmin();
        List<Admin> admins = adminDao.selectAllAdmin(offset, limit);
        map.put("count",i);
        map.put("msg","");
        map.put("code",0);
        map.put("data",admins);
        return map;
    }
}
